using UnityEngine;
using UnityEngine.Rendering;

[RequireComponent(typeof(AudioSource))]
public class ZombieInHome : Entity, IWeaponCartridgeEntity
{
	public enum ModeMove
	{
		Default,
		StandBreakLeg
	}

	public delegate void PlayerStrikeListener();

	public const float distStrikePlayer = 3.5f;

	public const float minDeltaTime = 0.05f;

	public const float distStrikeZombie = 3f;

	public const int ragdollEffects = 5;

	public static ZombieInHome[] ragdolls = new ZombieInHome[6];

	public static ZombieInHome[] entities = new ZombieInHome[0];

	public static string lastPlaySound;

	private static Rigidbody2D bodyMax = null;

	public static SortingGroup[] listSortGroup = new SortingGroup[0];

	public ZombieCharacteristic character;

	public float damageStrike = 1f;

	public PhysicsMaterial2D materialBody;

	[Range(0f, 2f)]
	public float scaleSpeedMove;

	public float speedMove;

	public Color colorBody = new Color(1f, 1f, 1f);

	public Color colorLegs = new Color(1f, 1f, 1f);

	public SpriteRenderer[] spritesOfBody = new SpriteRenderer[0];

	public SpriteRenderer[] spritesOfLegs = new SpriteRenderer[0];

	public Material materialHolesSkin;

	[Space(10f)]
	public float floor;

	public Rigidbody2D[] rigidbodies = new Rigidbody2D[0];

	public SpriteRenderer[] spritesRigidbodies = new SpriteRenderer[0];

	public HingeJoint2D[] muscleJoints = new HingeJoint2D[0];

	[Space(10f)]
	[Tooltip("Туловище для эффекта попаданий и для работы с физикой")]
	public Transform body;

	[Tooltip("Время для отключения физ.тел, используемые для пересечения с пулей")]
	public float timerBullet = 5f;

	public RuntimeAnimatorController controllerBreakLegs;

	public AudioClip[] soundsRage = new AudioClip[0];

	public AudioClip[] soundsPain = new AudioClip[0];

	public AudioClip[] soundsDie = new AudioClip[0];

	public AudioClip[] soundsSliceJoints = new AudioClip[0];

	public PartBodyDamage[] triggetHealth = new PartBodyDamage[0];

	public AnimationColliderTrigger[] animationTriggers = new AnimationColliderTrigger[0];

	[Tooltip("Триггеры. При подсчете очков не учитывать эти триггеры\n, когда у зомби сломаны ноги")]
	public Collider2D[] triggersBreakLegs = new Collider2D[0];

	public AnimationAreaDamage[] playAnimationArea = new AnimationAreaDamage[0];

	[Space(5f)]
	public Vector3 currentSpeed = default(Vector3);

	[HideInInspector]
	public Animator animator;

	private AnimatorStateInfo stateAnimator = default(AnimatorStateInfo);

	private AudioSource sound;

	private Vector3 startPositionBody = default(Vector3);

	private float angleBodyBullet;

	private float angleBodyTimer;

	private int angleBodyState = 123;

	private SpriteRenderer[] spritesMeat = new SpriteRenderer[0];

	private float maxScores = 40f;

	private RigidbodyRender[] ragdollRender = new RigidbodyRender[0];

	private Joint2D[] ragdollJoints = new Joint2D[0];

	private MuscleJointLimits[] limitsMuscles = new MuscleJointLimits[0];

	private MuscleTimeReflex[] reflexMuscles = new MuscleTimeReflex[0];

	private ModeMove modeMove;

	[HideInInspector]
	public EntityBehaviour entityBehaviour;

	public IZombieListener eventListener;

	private int r;

	private Vector2 force;

	private Collider2D[] colldersHit;

	private SpriteRenderer[] spritiesHit;

	public static Rigidbody2D[] tempListBody = new Rigidbody2D[0];

	public static SpriteRenderer[] tempListRender = new SpriteRenderer[0];

	public static RigidbodyRender[] tempRigidbodyRender = new RigidbodyRender[0];

	private float soundTimeMark;

	private bool rageIsPlayed;

	public static int maxRagdolls
	{
		get
		{
			return ragdolls.Length;
		}
		set
		{
			ragdolls = new ZombieInHome[value];
		}
	}

	public void OnSwitchTriggers(bool value)
	{
		if (isDead || !value)
		{
			return;
		}
		stateAnimator = animator.GetCurrentAnimatorStateInfo(0);
		int num = 0;
		for (r = 0; r < animationTriggers.Length; r++)
		{
			for (num = 0; num < animationTriggers[r].triggers.Length; num++)
			{
				animationTriggers[r].triggers[num].enabled = false;
			}
		}
		for (r = 0; r < animationTriggers.Length; r++)
		{
			if (stateAnimator.IsName(animationTriggers[r].nameOrTag))
			{
				for (num = 0; num < animationTriggers[r].triggers.Length; num++)
				{
					animationTriggers[r].triggers[num].enabled = true;
				}
			}
		}
	}

	public static bool PlayerStrike(Transform player, int numHits, PlayerStrikeListener onHitListener)
	{
		int num = 0;
		for (num = 0; num < entities.Length; num++)
		{
			if (numHits <= 0)
			{
				break;
			}
			if (entities[num].entityBehaviour.OnPlayerStrike("attack"))
			{
				numHits--;
				onHitListener();
			}
		}
		for (num = 0; num < entities.Length; num++)
		{
			if (numHits <= 0)
			{
				break;
			}
			if (entities[num].entityBehaviour.OnPlayerStrike(string.Empty))
			{
				numHits--;
				onHitListener();
			}
		}
		int num2 = numHits;
		int num3 = 0;
		while (num2 >= 0 && num3 < ragdolls.Length && ragdolls[num3] != null)
		{
			Vector3 position = player.position;
			float x = position.x;
			Vector3 position2 = ragdolls[num3].body.position;
			if (Mathf.Abs(x - position2.x) <= 3.5f)
			{
				for (int i = 0; i < ragdolls[num3].rigidbodies.Length; i++)
				{
					if (bodyMax == null || bodyMax.mass < ragdolls[num3].rigidbodies[i].mass)
					{
						bodyMax = ragdolls[num3].rigidbodies[i];
					}
				}
				if (bodyMax != null)
				{
					Vector3 eulerAngles = bodyMax.transform.rotation.eulerAngles;
					if (Mathf.Abs(Mathf.DeltaAngle(eulerAngles.z, 0f)) <= 45f)
					{
						Vector3 position3 = player.position;
						float x2 = position3.x;
						Vector2 worldCenterOfMass = bodyMax.worldCenterOfMass;
						if (Mathf.Abs(x2 - worldCenterOfMass.x) <= 3.5f)
						{
							ragdolls[num3].DisableRagdollPhysic(5f);
							bodyMax.AddForce(new Vector2(5f, 3f), ForceMode2D.Impulse);
							num2--;
							onHitListener();
							bodyMax = null;
						}
					}
				}
			}
			num3++;
		}
		bodyMax = null;
		return numHits == 0;
	}

	public static void UpdateSortingOrder()
	{
		listSortGroup = Object.FindObjectsOfType<SortingGroup>();
		for (int i = 0; i < listSortGroup.Length; i++)
		{
			listSortGroup[i].sortingOrder = 1;
			for (int j = 0; j < listSortGroup.Length; j++)
			{
				Vector3 position = listSortGroup[i].transform.position;
				float y = position.y;
				Vector3 position2 = listSortGroup[j].transform.position;
				if (y < position2.y)
				{
					listSortGroup[i].sortingOrder++;
				}
			}
		}
	}

	public static bool EnableRagdollEffects()
	{
		if (0.8f < Random.value)
		{
			return false;
		}
		int num = 0;
		for (int i = 0; i < entities.Length; i++)
		{
			if (!entities[i].isDead)
			{
				num++;
			}
			if (num > 5)
			{
				return false;
			}
		}
		return true;
	}

	private void Awake()
	{
		if (DamageOfSprite.enabledComponents && materialHolesSkin != null)
		{
			SpriteHoles.TestMaterial(materialHolesSkin);
		}
		animator = GetComponent<Animator>();
		animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;
		SetScaleSpeed(scaleSpeedMove);
		sound = GetComponent<AudioSource>();
		spritesMeat = GetComponentsInChildren<SpriteRenderer>(includeInactive: true);
		startPositionBody = body.localPosition;
		ragdollRender = new RigidbodyRender[rigidbodies.Length];
		for (r = 0; r < ragdollRender.Length; r++)
		{
			ragdollRender[r] = new RigidbodyRender(rigidbodies[r], spritesRigidbodies[r], base.transform, floor);
		}
		DisableRagdollPhysic();
		entities = Object.FindObjectsOfType<ZombieInHome>();
	}

	private void Start()
	{
		character.OnStartZombie(this);
		entityBehaviour = character.GetBehaviour(this);
		int num = 0;
		for (num = 0; num < triggetHealth.Length; num++)
		{
			triggetHealth[num].scaleDamage = Mathf.Floor(10f / triggetHealth[num].health * 100f) / 100f;
		}
		for (num = 0; num < base.areas.Length; num++)
		{
			base.areas[num].AddComponentListener<DestroyJoint>(OnDestroyJoint);
			base.areas[num].AddComponentListener<DestroyBodyJoints>(OnDestroyBodyJoints);
			base.areas[num].AddComponentListener<SpliceBody>(OnSpliceBody);
			base.areas[num].AddComponentListener<DamageOfSprite>(OnDamageSprite);
			for (r = 0; r < playAnimationArea.Length; r++)
			{
				if (base.areas[num].EventExists(playAnimationArea[r].state))
				{
					base.areas[num].AddListener(OnStateAreaActivation);
				}
			}
		}
		UpdateSortingOrder();
		WeaponCartridge.AddEntityTriggers(this);
	}

	private void OnDestroy()
	{
		WeaponCartridge.RemoveEntityTriggers(this);
		lastPlaySound = string.Empty;
		base.enabled = false;
		entities = Object.FindObjectsOfType<ZombieInHome>();
		if (eventListener != null)
		{
			eventListener.OnZombieDestroy(this);
		}
	}

	public void SetScaleSpeed(float scaleSpeed)
	{
		scaleSpeedMove = Mathf.Floor(scaleSpeed * 100f) / 100f;
		if (!isDead)
		{
			animator.SetFloat("speedMove", scaleSpeedMove);
		}
	}

	public void AddScaleSpeed()
	{
		SetScaleSpeed(Mathf.Lerp(scaleSpeedMove, 1.6f, Random.Range(50f, 100f) * 0.01f));
	}

	public void Stand()
	{
		if (!isDead)
		{
			animator.SetBool("move", value: false);
		}
	}

	public void SwitchMoveLame()
	{
		if (!isDead)
		{
			animator.SetBool("lame", value: true);
		}
	}

	public void SwitchMoveBreakLeg()
	{
		if (!isDead)
		{
			animator.SetBool("breakLeg", value: true);
		}
	}

	private void Update()
	{
		entityBehaviour.OnUpdate();
	}

	private void FixedUpdate()
	{
		if (!isDead)
		{
			return;
		}
		if (limitsMuscles.Length != 0)
		{
			Vector3 eulerAngles = body.rotation.eulerAngles;
			if (Mathf.Abs(Mathf.DeltaAngle(eulerAngles.z, 0f)) > 40f)
			{
				for (r = 0; r < limitsMuscles.Length; r++)
				{
					limitsMuscles[r].ResetLimits();
				}
				limitsMuscles = new MuscleJointLimits[0];
			}
		}
		for (r = 0; r < reflexMuscles.Length; r++)
		{
			reflexMuscles[r].UpdateReflex(Time.fixedDeltaTime);
		}
	}

	private void LateUpdate()
	{
		for (r = 0; r < ragdollRender.Length; r++)
		{
			ragdollRender[r].Update();
		}
		if (angleBodyTimer == 0f || isDead || angleBodyState != animator.GetCurrentAnimatorStateInfo(0).fullPathHash)
		{
			angleBodyTimer = 0f;
			return;
		}
		angleBodyTimer = Mathf.Max(0f, angleBodyTimer - Time.deltaTime);
		body.localRotation = Quaternion.Euler(0f, 0f, Mathf.Lerp(0f, angleBodyBullet, angleBodyTimer / 0.25f));
	}

	public void OnHitBullet(HitBullet hitBullet)
	{
		int num = 0;
		int num2 = 0;
		bool flag = hitBullet.raycastHit.collider.sharedMaterial.name == materialBody.name || hitBullet.scaleMaterial != 0f;
		if (hitBullet.raycastHit.collider.sharedMaterial == materialBody && maxScores != 0f && CheckTriggerModeMove(hitBullet.raycastHit.collider))
		{
			if (IsDeadFrame())
			{
				maxScores = Player.onStage.AddScoresHits(hitBullet.raycastHit.collider.gameObject, hitBullet.weapon.cartridge.GetScaleScoresBullet(), maxScores, 0.5f);
			}
			else
			{
				maxScores = Player.onStage.AddScoresHits(hitBullet.raycastHit.collider.gameObject, hitBullet.weapon.cartridge.GetScaleScoresBullet(), maxScores, 1f);
			}
		}
		HitTestArea(hitBullet.raycastHit.point, hitBullet.damage);
		num = 0;
		while (flag && num < triggetHealth.Length)
		{
			if (hitBullet.raycastHit.collider.gameObject == triggetHealth[num].partBody.gameObject)
			{
				health = HealthDamage(hitBullet.damage * triggetHealth[num].scaleDamage, health);
				break;
			}
			num++;
		}
		colldersHit = Physics2D.OverlapCircleAll(hitBullet.raycastHit.point, 0.3f, hitBullet.cartridgeRay.layerBodies);
		spritiesHit = new SpriteRenderer[colldersHit.Length];
		for (num = 0; num < colldersHit.Length; num++)
		{
			for (int i = 0; i < ragdollRender.Length; i++)
			{
				if (colldersHit[num].gameObject == ragdollRender[i].render.gameObject && (colldersHit[num].gameObject == hitBullet.raycastHit.collider.gameObject || colldersHit[num].transform == hitBullet.raycastHit.collider.transform.parent || colldersHit[num].transform.parent == hitBullet.raycastHit.collider.transform || colldersHit[num].transform.parent == hitBullet.raycastHit.collider.transform.parent))
				{
					spritiesHit[num] = ragdollRender[i].spriteRender;
					break;
				}
			}
		}
		for (num2 = 0; num2 < spritiesHit.Length; num2++)
		{
			for (num = 0; num < spritiesHit.Length; num++)
			{
				if (!(spritiesHit[num2] != null))
				{
					break;
				}
				if (num2 != num && spritiesHit[num2] == spritiesHit[num])
				{
					spritiesHit[num] = null;
				}
			}
		}
		if (flag && DamageOfSprite.enabledComponents)
		{
			for (num = 0; num < spritiesHit.Length; num++)
			{
				if (spritiesHit[num] != null)
				{
					SpriteHoles.AddHole(spritiesHit[num], hitBullet.raycastHit.point, materialHolesSkin);
					ShowMeat(spritiesHit[num].transform);
				}
			}
		}
		Vector3 eulerAngles = body.rotation.eulerAngles;
		float num3 = Mathf.Abs(Mathf.DeltaAngle(eulerAngles.z, 0f));
		if (isDead && colldersHit.Length != 0 && ragdollRender.Length != 0)
		{
			force = hitBullet.impulseDirection / colldersHit.Length;
			for (num2 = 0; num2 < ragdollRender.Length; num2++)
			{
				for (num = 0; num < spritiesHit.Length; num++)
				{
					if (spritiesHit[num] == ragdollRender[num2].spriteRender)
					{
						if (num3 < 30f)
						{
							rigidbodies[num2].AddForceAtPosition(force * 0.05f, hitBullet.raycastHit.point, ForceMode2D.Impulse);
						}
						else
						{
							rigidbodies[num2].AddForceAtPosition(force, hitBullet.raycastHit.point, ForceMode2D.Force);
						}
						break;
					}
				}
			}
		}
		rageIsPlayed = true;
		if (flag && Random.Range(0, 2) == 0)
		{
			PlaySoundPain();
		}
		if (!isDead)
		{
			Vector3 eulerAngles2 = body.localRotation.eulerAngles;
			if (eulerAngles2.z == 0f && (hitBullet.raycastHit.collider.gameObject == body.gameObject || hitBullet.raycastHit.collider.transform.parent == body.gameObject))
			{
				angleBodyBullet = (float)(-Random.Range(500, 1000)) / 100f;
				angleBodyTimer = 0.25f;
				angleBodyState = animator.GetCurrentAnimatorStateInfo(0).fullPathHash;
			}
		}
		colldersHit = new Collider2D[0];
		spritiesHit = new SpriteRenderer[0];
	}

	private bool CheckTriggerModeMove(Collider2D trigger)
	{
		if (modeMove == ModeMove.Default)
		{
			return true;
		}
		for (int i = 0; i < triggersBreakLegs.Length; i++)
		{
			if (triggersBreakLegs[i].GetInstanceID() == trigger.GetInstanceID())
			{
				return false;
			}
		}
		return true;
	}

	public override void Death()
	{
		if (isDead)
		{
			return;
		}
		base.Death();
		if (eventListener != null)
		{
			eventListener.OnZombieDeath(this);
		}
		CancelInvoke();
		Invoke("DisableRagdollPhysic", timerBullet);
		angleBodyBullet = 0f;
		angleBodyTimer = 0f;
		for (r = 0; r < ragdollRender.Length; r++)
		{
			ragdollRender[r].Enable(base.transform, base.transform);
		}
		limitsMuscles = new MuscleJointLimits[muscleJoints.Length];
		for (r = 0; r < limitsMuscles.Length; r++)
		{
			limitsMuscles[r] = new MuscleJointLimits(muscleJoints[r]);
		}
		if (EnableRagdollEffects())
		{
			reflexMuscles = new MuscleTimeReflex[muscleJoints.Length];
			for (r = 0; r < reflexMuscles.Length; r++)
			{
				reflexMuscles[r] = new MuscleTimeReflex(muscleJoints[r]);
			}
		}
		for (int i = 0; i < animationTriggers.Length; i++)
		{
			for (r = 0; r < animationTriggers[i].triggers.Length; r++)
			{
				UnityEngine.Object.Destroy(animationTriggers[i].triggers[r]);
			}
		}
		animationTriggers = new AnimationColliderTrigger[0];
		UpdateSortingOrder();
		if (soundsDie.Length != 0 && (!sound.isPlaying || StopSound(sound.clip, soundsPain) || StopSound(sound.clip, soundsRage)))
		{
			//sound.Stop();
			sound.clip = soundsDie[Random.Range(0, soundsDie.Length)];
			sound.Play();
			UnityEngine.Debug.Log("sound.Play (soundsDie)");
		}
		triggetHealth = new PartBodyDamage[0];
		if (ragdolls[ragdolls.Length - 1] != null)
		{
			UnityEngine.Object.Destroy(ragdolls[ragdolls.Length - 1].gameObject);
		}
		for (r = ragdolls.Length - 1; r > 0; r--)
		{
			ragdolls[r] = ragdolls[r - 1];
		}
		ragdolls[0] = this;
		entityBehaviour.OnDeath();
		UnityEngine.Object.Destroy(animator);
		animator = null;
	}

	private bool StopSound(AudioClip currentClip, AudioClip[] clips)
	{
		for (int i = 0; i < clips.Length; i++)
		{
			if (currentClip == clips[i])
			{
				return true;
			}
		}
		return false;
	}

	public void DisableRagdollPhysic()
	{
		if (isDead)
		{
			Vector3 eulerAngles = body.rotation.eulerAngles;
			if (Mathf.Abs(Mathf.DeltaAngle(eulerAngles.z, 0f)) < 45f)
			{
				DisableRagdollPhysic(timerBullet);
				return;
			}
		}
		if (isDead)
		{
			for (r = 0; r < ragdollRender.Length; r++)
			{
				if (ragdollRender[r].body.angularVelocity > 5f || ragdollRender[r].body.velocity.magnitude > 0.1f)
				{
					DisableRagdollPhysic(timerBullet);
					return;
				}
			}
			collidersBody = GetComponentsInChildren<Collider2D>(includeInactive: true);
			ragdollJoints = GetComponentsInChildren<Joint2D>(includeInactive: true);
			for (r = 0; r < collidersBody.Length; r++)
			{
				UnityEngine.Object.Destroy(collidersBody[r]);
			}
			for (r = 0; r < ragdollJoints.Length; r++)
			{
				UnityEngine.Object.Destroy(ragdollJoints[r]);
			}
			for (r = 0; r < ragdollRender.Length; r++)
			{
				UnityEngine.Object.Destroy(ragdollRender[r].body.gameObject);
			}
			collidersBody = new Collider2D[0];
			ragdollJoints = new Joint2D[0];
			rigidbodies = new Rigidbody2D[0];
			muscleJoints = new HingeJoint2D[0];
			ragdollRender = new RigidbodyRender[0];
			base.enabled = false;
			UpdateSortingOrder();
		}
		else
		{
			for (int i = 0; i < ragdollRender.Length; i++)
			{
				ragdollRender[i].Disable();
			}
		}
	}

	public void DisableRagdollPhysic(float time)
	{
		CancelInvoke("DisableRagdollPhysic");
		Invoke("DisableRagdollPhysic", time);
	}

	public void DamageFromArea(int damage = 1)
	{
		health = HealthDamage(damage, health);
	}

	public void AttackStrike()
	{
		entityBehaviour.OnAttack();
	}

	public void PlayerEventEath()
	{
		Player.onStage.ZombieBeginEath();
	}

	public void OnStateAreaActivation(AreaDamage area)
	{
		if (isDead || animator == null)
		{
			return;
		}
		animator.SetTrigger("pain");
		for (r = 0; r < playAnimationArea.Length; r++)
		{
			if (area.EventExists(playAnimationArea[r].state))
			{
				playAnimationArea[r].PlayState(this);
			}
		}
	}

	public void OnDamageSprite(DamageOfSprite areaComp)
	{
		PlaySoundOneClip(soundsSliceJoints[Random.Range(0, soundsSliceJoints.Length)]);
		r = 0;
		while (areaComp.list.Length >= 2 && r < areaComp.list.Length && areaComp.list[r] != null)
		{
			ShowMeat(areaComp.list[r].transform);
			r++;
		}
	}

	public void OnDestroyJoint(DestroyJoint areaComp)
	{
		PlaySoundOneClip(soundsSliceJoints[Random.Range(0, soundsSliceJoints.Length)]);
		Death();
	}

	public void OnDestroyBodyJoints(DestroyBodyJoints compJointsBody)
	{
		PlaySoundOneClip(soundsSliceJoints[Random.Range(0, soundsSliceJoints.Length)]);
		for (r = 0; r < ragdollRender.Length; r++)
		{
			if (ragdollRender[r].body == compJointsBody.body)
			{
				ragdollRender[r].Enable(base.transform, base.transform.parent);
				break;
			}
		}
		for (r = 0; r < reflexMuscles.Length; r++)
		{
			if (reflexMuscles[r].body == compJointsBody.body)
			{
				reflexMuscles[r].Destroy();
			}
		}
		compJointsBody = null;
	}

	public void OnSpliceBody(SpliceBody spliceBodyArea)
	{
		PlaySoundOneClip(soundsSliceJoints[Random.Range(0, soundsSliceJoints.Length)]);
		Death();
		tempListBody = (rigidbodies.Clone() as Rigidbody2D[]);
		tempListRender = (spritesRigidbodies.Clone() as SpriteRenderer[]);
		tempRigidbodyRender = (ragdollRender.Clone() as RigidbodyRender[]);
		rigidbodies = new Rigidbody2D[tempListBody.Length + 1];
		spritesRigidbodies = new SpriteRenderer[tempListBody.Length + 1];
		ragdollRender = new RigidbodyRender[tempListBody.Length + 1];
		for (r = 0; r < tempListBody.Length; r++)
		{
			rigidbodies[r] = tempListBody[r];
		}
		for (r = 0; r < tempListRender.Length; r++)
		{
			spritesRigidbodies[r] = tempListRender[r];
		}
		for (r = 0; r < tempRigidbodyRender.Length; r++)
		{
			ragdollRender[r] = tempRigidbodyRender[r];
		}
		rigidbodies[tempListBody.Length] = spliceBodyArea.newBody;
		spritesRigidbodies[tempListBody.Length] = spliceBodyArea.newRenderBody;
		ragdollRender[tempListBody.Length] = new RigidbodyRender(spliceBodyArea.newBody, spliceBodyArea.newRenderBody, base.transform, floor);
		collidersBody = new Collider2D[0];
		WeaponCartridge.UpdateEntityTriggers(this);
	}

	public void PlaySound(AudioClip audio)
	{
		if (!AudioListener.pause && sound != null && !isDead && sound.enabled && !sound.isPlaying)
		{
			//sound.Stop();
			sound.clip = audio;
			sound.Play();
		}
	}

	public void PlaySoundOnce(AudioClip audio)
	{
		if (!AudioListener.pause && lastPlaySound != audio.name && sound != null && sound.enabled)
		{
			//sound.Stop();
			sound.clip = audio;
			sound.Play();
			lastPlaySound = audio.name;
		}
	}

	public void PlaySoundOneClip(AudioClip audio)
	{
		if (!AudioListener.pause && lastPlaySound != audio.name && Time.time - soundTimeMark > 0.5f)
		{
			//sound.Stop();
			sound.clip = audio;
			sound.Play();
			lastPlaySound = audio.name;
		}
	}

	public void PlaySoundRage()
	{
		if (!rageIsPlayed && soundsRage.Length != 0)
		{
			PlaySoundOneClip(soundsRage[Random.Range(0, soundsRage.Length)]);
			rageIsPlayed = true;
		}
	}

	public void PlaySoundPain()
	{
		if (soundsPain.Length != 0)
		{
			PlaySound(soundsPain[Random.Range(0, soundsPain.Length)]);
		}
	}

	public void ShowMeat(Transform body)
	{
		int num = 0;
		while (true)
		{
			if (num < spritesMeat.Length)
			{
				if (spritesMeat[num] == null)
				{
					spritesMeat = GetComponentsInChildren<SpriteRenderer>(includeInactive: true);
					ShowMeat(body);
					return;
				}
				if (!spritesMeat[num].gameObject.activeSelf && spritesMeat[num].transform.parent == body)
				{
					break;
				}
				num++;
				continue;
			}
			return;
		}
		spritesMeat[num].gameObject.SetActive(value: true);
	}

	public void BreakHingeJoint(HingeJoint2D joint)
	{
		Death();
		JointAngleLimits2D limits = default(JointAngleLimits2D);
		if (joint != null)
		{
			limits.min = joint.limits.min - (float)Random.Range(30, 40);
			limits.max = joint.limits.max + (float)Random.Range(15, 40);
			if (limits.min > -360f && limits.max < 540f)
			{
				joint.limits = limits;
			}
		}
	}

	public void AnimatorCrossFade(string state)
	{
		if (!isDead && !animator.GetCurrentAnimatorStateInfo(0).IsName(state))
		{
			animator.CrossFade(state, 0.2f);
		}
	}

	public void AnimatorPlayInMove(string state)
	{
		if (speedMove <= 0f && !isDead && animator.GetCurrentAnimatorStateInfo(0).IsTag("move"))
		{
			animator.Play(state);
		}
		else if (ZombieBarricade.onStage != null)
		{
			AnimatorPlayStand(state);
		}
	}

	public void AnimatorPlayStand(string state)
	{
		if (IsStand())
		{
			AnimatorPlay(state);
		}
	}

	public void AnimatorPlay(string state)
	{
		if (!isDead && (!animator.GetCurrentAnimatorStateInfo(0).IsName(state) || animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 0.5f))
		{
			animator.Play(state);
		}
	}

	public void SwitchBreakLeg(string state)
	{
		if (modeMove != ModeMove.StandBreakLeg && !isDead)
		{
			animator.runtimeAnimatorController = controllerBreakLegs;
			animator.Play(state, 0, 0f);
			modeMove = ModeMove.StandBreakLeg;
			if (eventListener != null)
			{
				eventListener.OnSwitchStandBreakLeg(this);
			}
		}
	}

	public bool IsStand()
	{
		return Mathf.Abs(Vector3.Distance(body.localPosition, startPositionBody)) < 0.5f || modeMove == ModeMove.StandBreakLeg;
	}

	public void StartMove(float speedMove)
	{
		this.speedMove = speedMove;
	}

	Transform IWeaponCartridgeEntity.transform
	{ get {
		return base.transform;
	} }

	GameObject IWeaponCartridgeEntity.gameObject
	{ get {
		return base.gameObject;
	} }

	bool IWeaponCartridgeEntity.CompareTag(string tag)
	{
		return CompareTag(tag);
	}
}
